import {api} from '@/pages/product/detail/libs/api.js';
let _self;
export const index =  {
	props: {
		dataInfo:{type:Object,default:{}},
		product:{type:Object,default:{}},
		changeInfo:{type:Object,default:{}},
	},
	watch:{

	},
	data() {
		return {
			amount: 1,	
			specsIndex:0,
			formData:this.dataInfo,
			host:process.env.HOST,
			radios: [{checked: true},{checked: false},{checked: false}],
			dateNow: new Date().Format("yyyy-MM-dd"),
		}
	},
	
	mounted() {
		_self = this;
		
		let sIndex=this.dataInfo["specs_index"]>0?this.dataInfo["specs_index"]:0;
		
		if(this.dataInfo["inventory_code"]){
			for(let index in this.product.specs){
				let item=this.product.specs[index];
				if(item["inv_name"]==this.dataInfo["inventory_code"]) this.dataInfo["specs_index"]=index;
			}
		}
		
		
		this.amount=this.dataInfo["box_num"]>0?this.dataInfo["box_num"]:1;
		this.specsIndex=this.dataInfo["specs_index"]>0?this.dataInfo["specs_index"]:0;
		this.initData();
	},

	methods: {
		initData: async function(){
			let specs=this.product.specs[this.specsIndex];
			/*this.changeData["length"]=specs["length"];
			this.changeData["width"]=specs["width"];
			this.changeData["box_num"]=this.amount;
			this.changeData["piece_num"]=specs["roll"];
			this.changeData["price"]=Number(specs["price"]/specs["roll"]);
			this.changeData["roll_num"]=specs["roll"];
			this.changeData["total"]=Number(specs["price"]*this.amount).toFixed(2);
			this.changeData["specs_index"]=this.specsIndex;
			this.changeData["inventory_code"]=specs["inv_name"];//设置存货编码*/
			
			this.formData["total"]=Number(specs["price"]*this.amount).toFixed(2);
			
			let changeData=Object.assign({},{
				"length":specs["length"],
				"width":specs["width"],
				"box_num":this.amount,
				"piece_num":specs["roll"],
				"price":Number(specs["price"]/specs["roll"]),
				"box_price":Number(specs["price"]),
				"roll_num":Number(specs["roll"]*this.amount),
				"total":Number(specs["price"]*this.amount).toFixed(2),
				"specs_index":this.specsIndex,
				"inventory_code":specs["inv_name"]
			});
			//更新父组建表单数据
			this.$emit('update:changeInfo', changeData);
		},
		
		radioClick(index) {
			this.specsIndex=index;
			this.initData();
		},
		valChange(e) {
			this.amount=e.value
			this.initData();
		}
	},
}